<?php

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use App\Services\HireService;
use Illuminate\Http\Request;

class HireController extends Controller
{
    protected $HireService;
    public function __construct(HireService $HireService)
    {
        $this->HireService = $HireService;
    }

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request)
    {
        $title = $request->title;
        $pageSize = $request->pageSize ?: 10;
        $page = $request->page ?: 1;
        $skip = $page * $pageSize - $pageSize;

        $sql = $this->HireService->get($title);
        $total = $sql->count();
        $data = $sql->skip($skip)->take($pageSize)->orderBy('created_at','desc')->get();
        return response()->json(['code' => 200, 'message' => '操作成功','page'=>$page,'pageSize'=>$pageSize,'total'=>$total,'data'=>$data]);
    }
}
